#include "Ctrl.h"


#if MediatorPattern_


class Country;


// 联合国机构
class UnitedNations 
{
public :
	virtual void Declare(string  _message, Country* _colleague) = 0;
};

// 国家
class Country
{
protected:
	UnitedNations* m_pMediator;
public:
	Country(UnitedNations* _pMediator) {
		m_pMediator = _pMediator;
	}
};


class USA : public Country
{
public:
	USA(UnitedNations* _pMediator) : Country(_pMediator){}
	void Declare(string _message) {
		m_pMediator->Declare(_message, this);
	}
	void GetMessage(string _message) {
		cout << "美国获得对方信息：" << _message << endl;
	}
};

class Iraq : public Country
{
public:
	Iraq(UnitedNations* _pMediator) : Country(_pMediator) {}
	void Declare(string _message) {
		m_pMediator->Declare(_message, this);
	}
	void GetMessage(string _message) {
		cout << "伊拉克获得对方信息：" << _message << endl;
	}
};

// 联合国安全理事会
class UnitedNationsSecurityCouncil : public UnitedNations
{
private:
	USA* m_pColleague1;
	Iraq* m_pColleague2;
public:
	void SetColleague1(USA* _pUSA) {
		m_pColleague1 = _pUSA;
	}
	void SetColleague2(Iraq* _pIraq) {
		m_pColleague2 = _pIraq;
	}
	void Declare(string _message, Country* _pConutry) override {
		if (_pConutry == m_pColleague1) {
			m_pColleague2->GetMessage(_message);
		}
		else if (_pConutry == m_pColleague2) {
			m_pColleague1->GetMessage(_message);
		}
	}
};



int main() {
	UnitedNationsSecurityCouncil* pUNSC = new UnitedNationsSecurityCouncil();
	USA* pC1 = new USA(pUNSC);
	Iraq* pC2 = new Iraq(pUNSC);

	pUNSC->SetColleague1(pC1);
	pUNSC->SetColleague2(pC2);

	pC1->Declare("不准研制核武器，否则要发动战争！");
	pC2->Declare("我们没有核武器，也不怕侵略！");

}


#endif